package com.shujia.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo4UseModel {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession
      .builder()
      .master("local")
      .appName("line")
      .getOrCreate()

    import spark.implicits._
    import org.apache.spark.sql.functions._

    /**
      * 加载已经保存好的模型
      *
      */

    val model: LogisticRegressionModel = LogisticRegressionModel.load("data/model")


    /**
      * 使用模型预测未知的数据
      * 0 1:4.7 2:3.1 3:2.3 4:101.4 5:66.6 6:55.1 7:80
      */
    val vector: linalg.Vector = Vectors.dense(Array(4.7, 3.1, 2.3, 101.4, 66.6, 55.1, 80.0))

    val y: Double = model.predict(vector)

    println(y)

  }

}
